import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {CrawlNamespaceForm, CrawlNamespaceNameVO, CrawlNamespacePageResult, CrawlNamespaceQuery,} from './types';

/**
 * 爬虫空间分页列表
 *
 * @param data
 */
export function getPage(data: CrawlNamespaceQuery): AxiosPromise<CrawlNamespacePageResult> {
	return request({
		url: '/api/v1/crawl/namespace/page',
		method: 'post',
		data: data
	});
}

/**
 * 爬虫空间下拉列表
 */
export function getNameList(): AxiosPromise<CrawlNamespaceNameVO[]> {
	return request({
		url: '/api/v1/crawl/namespace/nameList',
		method: 'get'
	});
}

/**
 * 爬虫空间表单数据
 *
 * @param id
 */
export function getForm(id: number): AxiosPromise<CrawlNamespaceForm> {
	return request({
		url: '/api/v1/crawl/namespace/' + id + '/form',
		method: 'get'
	});
}

/**
 * 新增爬虫空间
 *
 * @param data
 */
export function add(data: CrawlNamespaceForm) {
	return request({
		url: '/api/v1/crawl/namespace/add',
		method: 'post',
		data: data
	});
}

/**
 * 修改爬虫空间
 *
 * @param id
 * @param data
 */
export function update(id: number, data: CrawlNamespaceForm) {
	return request({
		url: '/api/v1/crawl/namespace/' + id,
		method: 'put',
		data: data
	});
}

/**
 * 删除爬虫空间
 */
export function del(ids: string) {
	return request({
		url: '/api/v1/crawl/namespace/' + ids,
		method: 'delete'
	});
}
